package org.huawei260.OD260;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

/**
 * @Auther: qingle
 * @Date: 2024/8/22-2:12
 * @Description:
 *删除字符串中出现次数最少的字符
 *如果多个字符出现次数一样则都删除
 *
 * 这道题太基础，训练基本功
 * 我的思路：
 * 1.统计每个字符出现的次数
 * 用一个map来统计每个字符出现的次数
 * HashMap<Character, Integer> map = new HashMap<>();
 * map.put(c, map.getOrDefault(c, 0) + 1);
 * 2.找出出现次数最少的字符的数量 [可能遇到多个字符，用set装]
 * map.values() 最小的值对应的map是哪个
 * int min = Math.MAX_VALUE;
 * for (int count : charCountMap.values()) {
 * if (count < minCount) {
 * min = count;
 }
 *
 * 3.删除出现次数最少的字符
 * Stringbuilder sb = new Stringbuilder();
 * for(map.Entry<Character, Integer> entry : map.entrySet()) {
 * if (map.entrySet() != min) {
 * sb.append(entry);
 }
 *
 *
 * 重新进行拼接
 *
 * 4.返回删除后的字符串
 * return sb.toString() == "" ? "empty" : sb.toString();
 *
 *
 * @version: 1.0
 */
public class O0017_删除最少字符_moxie2 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String res = sc.nextLine();
		System.out.println(deleteLeastCharacter(res));
	}

	private static String deleteLeastCharacter(String res) {
		// 1.统计字符出现的次数
		HashMap<Character, Integer> map = new HashMap<>();
		for (Character c: res.toCharArray()) {
			map.put(c, map.getOrDefault(c, 0) + 1);
		}
		// 2.找到最小的数字
		int min = res.length();
		for (int count: map.values()) {
			if (min > count) {
				min = count;
			}
		}
		// 3.找到最小数字对应的字符
		HashSet<Character> set = new HashSet<>();
		for (Map.Entry<Character, Integer> key: map.entrySet()) {
			if (key.getValue() == min) {
				set.add(key.getKey());
			}
		}
		// 4.拼接字符串
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < res.length(); i++) {
			if(!set.contains(res.charAt(i))) {
				sb.append(res.charAt(i));
			}
		}
		// 5.返回新字符串
		return res.isEmpty() ? "empty" : sb.toString();
	}

}
